package edu.gatech.cs2340.OregonTrail.EventSystem;

import javax.swing.event.EventListenerList;

public class CommunicationModule implements CommCoordinator {
	EventListenerList guiListeners;
	EventListenerList actorListeners;
	
	public CommunicationModule(){
		guiListeners = new EventListenerList();
		actorListeners =  new EventListenerList();
	}
	
	public void AddGUIListener(GUIListener listener) {
		guiListeners.add(GUIListener.class, listener);
	}
	
	public void ThrowGUIEvent(GUIEvent e){
		Object[] listeners = guiListeners.getListenerList();
	     // loop through each listener and pass on the event if needed
	     int numListeners = listeners.length;
	     for (int i = 0; i<numListeners; i+=2) 
	     {
	          if (listeners[i]==GUIListener.class) 
	          {
	               // pass the event to the listeners event dispatch method
	                ((GUIListener)listeners[i+1]).guiActionPerformed(e);
	          }            
	     }
	}


	public void AddActorListener(ActorListener listener) {
		actorListeners.add(ActorListener.class, listener);
		
	}

	@Override
	public void ThrowActorEvent(ActorEvent e) {
		Object[] listeners = actorListeners.getListenerList();
	     // loop through each listener and pass on the event if needed
	     int numListeners = listeners.length;
	     for (int i = 0; i<numListeners; i+=2) 
	     {
	          if (listeners[i]==ActorListener.class) 
	          {
	               // pass the event to the listeners event dispatch method
	                ((ActorListener)listeners[i+1]).actorActionPerformed(e);
	          }            
	     }
		
	}

}
